package com.max.rabbitmq.learn.direct;

import com.max.rabbitmq.learn.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * @description 静态路由模式接收者1
 * @author yandong
 * @create 2021年4月07日 10:29:28
 */
public class Recv1 {
    public static void main(String[] args) throws IOException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        String genQueue = channel.queueDeclare().getQueue();

        channel.queueBind(genQueue, "exchange.max.direct", "error");

        channel.basicConsume(genQueue, false, (consumerTag, message) -> {
            System.out.println("/****************************/");
            System.out.println("recv from exchange =" + message.getEnvelope().getExchange());
            System.out.println("routeKey = " + message.getEnvelope().getRoutingKey());
            System.out.println("messageId = " + message.getProperties().getMessageId());
            System.out.println("message = " + new String(message.getBody(), "UTF-8"));
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
        }, consumerTag -> {

        });

    }
}
